﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WebServiceClient
{
    public partial class UploadForm : Form
    {
        private static Helpers help = new Helpers();
        private static AddAlgorithm addAlg = new AddAlgorithm();
        private static int countGroup;

        public UploadForm()
        {
            InitializeComponent();
        }

        private void FillTreeView()
        {
            var groups = help.GetGroups(Form1.Login, Form1.Password);
            countGroup = groups.Count;

            for (int i = 0; i < groups.Count; i++)
            {
                TreeNode node= treeViewRights.Nodes.Add(groups[i]);
                node.Nodes.Add("read/execute");
                node.Nodes.Add("write");
            } 
        }

        private void UploadForm_Load(object sender, EventArgs e)
        {
            FillTreeView();
            treeViewRights.ExpandAll();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Hide();
        }

        private void buttonUpload_Click(object sender, EventArgs e)
        {
            List<bool> read = new List<bool>();
            List<bool> write = new List<bool>();
            for (int i = 0; i < countGroup; i++)
            {
                read.Add(treeViewRights.Nodes[i].Nodes[0].Checked);
                write.Add(treeViewRights.Nodes[i].Nodes[1].Checked);
            }
            addAlg.Add(Form1.Login, Form1.Password, textBoxName.Text, textBoxDesc.Text, textBoxAlg.Text, read, write);
            MessageBox.Show("The algorithm has been successfully added!");
            Hide();
        }
    }
}
